﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace CipherBox
{
    public partial class KeyGeneratorDialog : Form
    {
        protected SaveKeyPath m_Callback;
        public KeyGeneratorDialog(SaveKeyPath callback)
        {
            m_Callback = callback;
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            saveFileDialog1.ShowDialog();
            if (saveFileDialog1.FileName != string.Empty)
            {
                textBox1.Text = saveFileDialog1.FileName;
            }
        }
        private bool m_Capture = false;
        StreamWriter fs;
        Permutator.Permutations p;
        string alp = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        private void button1_Click(object sender, EventArgs e)
        {
            buttonstart.Enabled = false;
            buttonstop.Enabled = true;
            p = new Permutator.Permutations(alp.ToCharArray(), 5);
            m_Capture = true;
            fs = File.AppendText(textBox1.Text);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            buttonsave.Enabled = true;
            buttonstart.Enabled = true;
            buttonstop.Enabled = false;
            m_Capture = false;
            fs.Close();
        }

        private void panel1_MouseMove(object sender, MouseEventArgs e)
        {
            if (m_Capture)
            {
                fs.Write(p[(e.X * e.Y * e.X) % p.Length]);
                int val = (int)fs.BaseStream.Length / 1024;

                if (val > progressBar1.Maximum)
                {
                    progressBar1.Value = progressBar1.Maximum;
                }
                if (val < progressBar1.Maximum && val > 0)
                {
                    progressBar1.Value = val;
                }
            }
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            m_Callback(textBox1.Text);
            this.Close();
        }
    }
}
